package cqrtplm.listener;

import cn.hutool.extra.spring.SpringUtil;
import com.hustcad.plm.pdm.workflow.annotion.CustomListener;
import com.hustcad.plm.pdm.workflow.annotion.CustomListenerField;
import com.hustcad.plm.pdm.workflow.model.constant.ProcessConstant;
import cqrtplm.service.GetCADDocumentService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.impl.el.FixedValue;

@CustomListener(
        category = "润通",
        description = "转阶段检查"
)
@Slf4j
public class RTTransitionStageCheckListener implements ExecutionListener {
    @CustomListenerField(description = "阶段(S、A、B)", defaultValue = "", required = true)
    private FixedValue stage;
    @Override
    public void notify(DelegateExecution delegateExecution) {
        long l = System.currentTimeMillis();
        String workFlowContainerId = delegateExecution.getProcessInstanceBusinessKey();
        if (StringUtils.isBlank(workFlowContainerId)) {
            workFlowContainerId = delegateExecution.getVariable(ProcessConstant.WORK_FLOW_CONTAINER_ID).toString();
        }
        GetCADDocumentService flowControlService = SpringUtil.getBean(GetCADDocumentService.class);
        flowControlService.transitionStageCheck(workFlowContainerId, stage.getExpressionText());
    }
}
